﻿Imports System.Windows.Forms
Imports System.Drawing
Public Class frmMatrizVaCo
    Private Sub cmdGenerar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MessageBox.Show("Matriz de Varianzas y Covarianzas generada exitósamente", TitMsj, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub frmMatrizVaCo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cmbVariacion.SelectedIndex = 0
    End Sub
    Private Sub dgMatrizVarianCovarian_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgMatrizVarianCovarian.CellMouseClick
        Dim Colum, Fila As Integer
        Dim grid As DataGridView = sender
        Dim pt As Point = grid.PointToClient(Control.MousePosition)

        If e.Button = Windows.Forms.MouseButtons.Right Then
            Colum = e.ColumnIndex
            Fila = e.RowIndex
            If Colum < 0 Or Fila < 0 Then
                Exit Sub
            End If

            With Me.dgMatrizVarianCovarian
                Dim Hitest As DataGridView.HitTestInfo = .HitTest(e.X, e.Y)
                If Hitest.Type - 1 = DataGridViewHitTestType.Cell Then
                    .CurrentCell = .Rows(Fila).Cells(Colum)
                End If
            End With

            If dgMatrizVarianCovarian.AllowUserToAddRows = True Then

                If dgMatrizVarianCovarian.Rows.Count > 1 Then

                    Me.ContextMenuStrip1.Show(dgMatrizVarianCovarian, pt.X, pt.Y)

                End If

            Else

                If dgMatrizVarianCovarian.Rows.Count > 0 Then

                    Me.ContextMenuStrip1.Show(dgMatrizVarianCovarian, pt.X, pt.Y)

                End If

            End If


        End If
    End Sub

    Private Sub ExportarVolatilidadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportarVolatilidadToolStripMenuItem.Click
        Cursor = Cursors.WaitCursor
        Exportar_Excel(dgMatrizVarianCovarian)
        Cursor = Cursors.Default
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Cargar_Datagrid()
    End Sub
    Private Sub Cargar_Datagrid()
        Dim dtMatriz As New DataTable
        Dim Alist As New ArrayList
        Dim num As Double
        Dim i As Integer

        dtMatriz.Columns.Add("Tipo")
        dtMatriz.Columns.Add("Pos Horizontal")
        dtMatriz.Columns.Add("TC US$")
        dtMatriz.Columns.Add("O/N")
        dtMatriz.Columns.Add("15 días")
        dtMatriz.Columns.Add("30 días")
        dtMatriz.Columns.Add("60 días")
        dtMatriz.Columns.Add("90 días")
        dtMatriz.Columns.Add("180 días")
        dtMatriz.Columns.Add("Bono 1 Año")
        dtMatriz.Columns.Add("Bono 2 Años")
        dtMatriz.Columns.Add("Bono 3 Años")
        dtMatriz.Columns.Add("Bono 4 Años")
        dtMatriz.Columns.Add("Bono 5 Años")
        dtMatriz.Columns.Add("ALICORC1")
        dtMatriz.Columns.Add("ALICORI1")
        dtMatriz.Columns.Add("ATACOI1")
        dtMatriz.Columns.Add("AUSTRAC1")
        dtMatriz.Columns.Add("BACKUAC1")
        dtMatriz.Columns.Add("BACKUBC1")
        dtMatriz.Columns.Add("BACKUSI1")
        dtMatriz.Columns.Add("BAP")
        dtMatriz.Columns.Add("BUENAAC1")
        dtMatriz.Columns.Add("BUENABC1")
        dtMatriz.Columns.Add("CEMLIMC1")
        dtMatriz.Columns.Add("CEMLIMI1")
        dtMatriz.Columns.Add("Cerro Verde")
        dtMatriz.Columns.Add("CIPORAC1")
        dtMatriz.Columns.Add("CPACASC1")
        dtMatriz.Columns.Add("EDEGELC1")
        dtMatriz.Columns.Add("Egenor")
        dtMatriz.Columns.Add("Fenix")
        dtMatriz.Columns.Add("FERREYC1")
        dtMatriz.Columns.Add("GRAMONC1")
        dtMatriz.Columns.Add("Hidrandina")
        dtMatriz.Columns.Add("A2")
        dtMatriz.Columns.Add("EDELNOC1")
        dtMatriz.Columns.Add("BVN")
        dtMatriz.Columns.Add("LUSURC1")
        dtMatriz.Columns.Add("MILPOAC1")
        dtMatriz.Columns.Add("MILPOBC1")
        dtMatriz.Columns.Add("MILPOI1")
        dtMatriz.Columns.Add("MINSURI1")
        dtMatriz.Columns.Add("PCU")
        dtMatriz.Columns.Add("VOLCABC1")
        dtMatriz.Columns.Add("Ecuador")
        dtMatriz.Columns.Add("Venezuela")
        dtMatriz.Columns.Add("Mexico")
        dtMatriz.Columns.Add("Panama")

        num = 0.5

        Alist.Add("PERÚ DÓLARES")
        Alist.Add("TC US$")
        Alist.Add("100.0000%")
        For i = 3 To dtMatriz.Columns.Count - 1

            Alist.Add(FormatPercent(num))

            num = num + 0.01

        Next i

        dtMatriz.Rows.Add(Alist.ToArray)

        Alist.Clear()

        num = 0.5

        Alist.Add("PERÚ DÓLARES")
        Alist.Add("ON")
        Alist.Add(FormatPercent(num))

        num = num + 0.01
        Alist.Add("100.0000%")
        For i = 3 To dtMatriz.Columns.Count - 2

            Alist.Add(FormatPercent(num))

            num = num + 0.01

        Next i

        dtMatriz.Rows.Add(Alist.ToArray)

        dgMatrizVarianCovarian.DataSource = dtMatriz








    End Sub
End Class